{
  "nbformat": 4,
  "nbformat_minor": 0,
  "metadata": {
    "colab": {
      "provenance": []
    },
    "kernelspec": {
      "name": "python3",
      "display_name": "Python 3"
    },
    "language_info": {
      "name": "python"
    }
  },
  "cells": [
    {
      "cell_type": "markdown",
      "source": [
        "<b>Use Gemini and ChatGPT to learn from two capable teachers</b>\n",
        "\n",
        "Use Google's latest model release, Gemini, to teach you what you want to know and compare those with ChatGPT's responses.\n",
        "\n",
        "The models are specifically prompted not to generate extra text to make it easier to compare any differences."
      ],
      "metadata": {
        "id": "ZWhWniBGu3_Y"
      }
    },
    {
      "cell_type": "code",
      "source": [
        "#@title Configure Gemini API key\n",
        "\n",
        "# access your Gemini API key\n",
        "\n",
        "import google.generativeai as genai\n",
        "from google.colab import userdata\n",
        "\n",
        "gemini_api_secret_name = 'GOOGLE_API_KEY'  # @param {type: \"string\"}\n",
        "\n",
        "try:\n",
        "  GOOGLE_API_KEY=userdata.get(gemini_api_secret_name)\n",
        "  genai.configure(api_key=GOOGLE_API_KEY)\n",
        "except userdata.SecretNotFoundError as e:\n",
        "   print(f'''Secret not found\\n\\nThis expects you to create a secret named {gemini_api_secret_name} in Colab\\n\\nVisit https://makersuite.google.com/app/apikey to create an API key\\n\\nStore that in the secrets section on the left side of the notebook (key icon)\\n\\nName the secret {gemini_api_secret_name}''')\n",
        "   raise e\n",
        "except userdata.NotebookAccessError as e:\n",
        "  print(f'''You need to grant this notebook access to the {gemini_api_secret_name} secret in order for the notebook to access Gemini on your behalf.''')\n",
        "  raise e\n",
        "except Exception as e:\n",
        "  # unknown error\n",
        "  print(f\"There was an unknown error. Ensure you have a secret {gemini_api_secret_name} stored in Colab and it's a valid key from https://makersuite.google.com/app/apikey\")\n",
        "  raise e\n",
        "\n",
        "model = genai.GenerativeModel('gemini-pro')"
      ],
      "metadata": {
        "cellView": "form",
        "id": "HAg5Vlk-TjdX"
      },
      "execution_count": 16,
      "outputs": []
    },
    {
      "cell_type": "code",
      "source": [
        "#@title Configure OpenAI API key\n",
        "\n",
        "# access your OpenAI API key\n",
        "\n",
        "# installing llmx first isn't necessary but avoids a confusing error when installing openai\n",
        "!pip install -q llmx\n",
        "!pip install -q openai\n",
        "from openai import OpenAI\n",
        "\n",
        "openai_api_secret_name = 'OPENAI_API_KEY'  # @param {type: \"string\"}\n",
        "\n",
        "try:\n",
        "  OPENAI_API_KEY=userdata.get(openai_api_secret_name)\n",
        "  client = OpenAI(\n",
        "    api_key=OPENAI_API_KEY\n",
        "  )\n",
        "except userdata.SecretNotFoundError as e:\n",
        "   print(f'''Secret not found\\n\\nThis expects you to create a secret named {openai_api_secret_name} in Colab\\n\\nVisit https://platform.openai.com/api-keys to create an API key\\n\\nStore that in the secrets section on the left side of the notebook (key icon)\\n\\nName the secret {openai_api_secret_name}''')\n",
        "   raise e\n",
        "except userdata.NotebookAccessError as e:\n",
        "  print(f'''You need to grant this notebook access to the {openai_api_secret_name} secret in order for the notebook to access Gemini on your behalf.''')\n",
        "  raise e\n",
        "except Exception as e:\n",
        "  # unknown error\n",
        "  print(f\"There was an unknown error. Ensure you have a secret {openai_api_secret_name} stored in Colab and it's a valid key from https://platform.openai.com/api-keys\")\n",
        "  raise e\n"
      ],
      "metadata": {
        "id": "yFv1abRcv2P2",
        "cellView": "form"
      },
      "execution_count": 17,
      "outputs": []
    },
    {
      "cell_type": "code",
      "source": [
        "#@title Ask a question!\n",
        "\n",
        "text = 'Write a python function that calculates the distance between any two latitudes and longitudes on earth' # @param {type:\"string\"}\n",
        "\n",
        "# ask Gemini\n",
        "model = genai.GenerativeModel('gemini-pro')\n",
        "chat = model.start_chat(history=[])\n",
        "\n",
        "response = chat.send_message('%s -- Please answer as concisely as you can, avoiding any extra conversation or text' % text)\n",
        "gemini_response = response.text\n",
        "\n",
        "# ask ChatGPT\n",
        "completion = client.chat.completions.create(\n",
        "  model=\"gpt-3.5-turbo\",\n",
        "  messages=[\n",
        "    {\"role\": \"user\", \"content\": '%s -- Please answer as concisely as you can, avoiding any extra conversation or text' % text}\n",
        "  ]\n",
        ")\n",
        "\n",
        "openai_response = completion.choices[0].message.content\n",
        "\n",
        "# render the diff\n",
        "\n",
        "# importing these every execution is unnecessary but avoids another notebook cell\n",
        "from IPython.display import HTML\n",
        "import difflib\n",
        "\n",
        "# omit the legend to slim down the UI\n",
        "difflib.HtmlDiff._legend = ''\n",
        "\n",
        "HTML(difflib.HtmlDiff().make_file(gemini_response.splitlines(), openai_response.splitlines(), 'Gemini', 'ChatGPT'))"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 923
        },
        "cellView": "form",
        "id": "timFyiyRYEqz",
        "outputId": "781353b5-53c4-46ae-f01f-0aea2d46a1fe"
      },
      "execution_count": 18,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "<IPython.core.display.HTML object>"
            ],
            "text/html": [
              "\n",
              "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"\n",
              "          \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n",
              "\n",
              "<html>\n",
              "\n",
              "<head>\n",
              "    <meta http-equiv=\"Content-Type\"\n",
              "          content=\"text/html; charset=utf-8\" />\n",
              "    <title></title>\n",
              "    <style type=\"text/css\">\n",
              "        table.diff {font-family:Courier; border:medium;}\n",
              "        .diff_header {background-color:#e0e0e0}\n",
              "        td.diff_header {text-align:right}\n",
              "        .diff_next {background-color:#c0c0c0}\n",
              "        .diff_add {background-color:#aaffaa}\n",
              "        .diff_chg {background-color:#ffff77}\n",
              "        .diff_sub {background-color:#ffaaaa}\n",
              "    </style>\n",
              "</head>\n",
              "\n",
              "<body>\n",
              "    \n",
              "    <table class=\"diff\" id=\"difflib_chg_to7__top\"\n",
              "           cellspacing=\"0\" cellpadding=\"0\" rules=\"groups\" >\n",
              "        <colgroup></colgroup> <colgroup></colgroup> <colgroup></colgroup>\n",
              "        <colgroup></colgroup> <colgroup></colgroup> <colgroup></colgroup>\n",
              "        <thead><tr><th class=\"diff_next\"><br /></th><th colspan=\"2\" class=\"diff_header\">Gemini</th><th class=\"diff_next\"><br /></th><th colspan=\"2\" class=\"diff_header\">ChatGPT</th></tr></thead>\n",
              "        <tbody>\n",
              "            <tr><td class=\"diff_next\" id=\"difflib_chg_to7__1\"><a href=\"#difflib_chg_to7__1\">n</a></td><td class=\"diff_header\" id=\"from7_1\">1</td><td nowrap=\"nowrap\"><span class=\"diff_sub\">```python</span></td><td class=\"diff_next\"><a href=\"#difflib_chg_to7__1\">n</a></td><td class=\"diff_header\"></td><td nowrap=\"nowrap\"></td></tr>\n",
              "            <tr><td class=\"diff_next\"></td><td class=\"diff_header\" id=\"from7_2\">2</td><td nowrap=\"nowrap\">import&nbsp;math</td><td class=\"diff_next\"></td><td class=\"diff_header\" id=\"to7_1\">1</td><td nowrap=\"nowrap\">import&nbsp;math</td></tr>\n",
              "            <tr><td class=\"diff_next\"></td><td class=\"diff_header\" id=\"from7_3\">3</td><td nowrap=\"nowrap\"></td><td class=\"diff_next\"></td><td class=\"diff_header\" id=\"to7_2\">2</td><td nowrap=\"nowrap\"></td></tr>\n",
              "            <tr><td class=\"diff_next\"><a href=\"#difflib_chg_to7__2\">n</a></td><td class=\"diff_header\" id=\"from7_4\">4</td><td nowrap=\"nowrap\">def&nbsp;distance(lat1,&nbsp;lon1,&nbsp;lat2,&nbsp;lon2):</td><td class=\"diff_next\"><a href=\"#difflib_chg_to7__2\">n</a></td><td class=\"diff_header\" id=\"to7_3\">3</td><td nowrap=\"nowrap\">def&nbsp;<span class=\"diff_add\">calculate_</span>distance(lat1,&nbsp;lon1,&nbsp;lat2,&nbsp;lon2):</td></tr>\n",
              "            <tr><td class=\"diff_next\"></td><td class=\"diff_header\" id=\"from7_5\">5</td><td nowrap=\"nowrap\"><span class=\"diff_sub\">&nbsp;&nbsp;\"\"\"Calculates&nbsp;the&nbsp;distance&nbsp;between&nbsp;two&nbsp;latitudes&nbsp;and&nbsp;longitudes.</span></td><td class=\"diff_next\"></td><td class=\"diff_header\" id=\"to7_4\">4</td><td nowrap=\"nowrap\"><span class=\"diff_add\">&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;Convert&nbsp;degrees&nbsp;to&nbsp;radians</span></td></tr>\n",
              "            <tr><td class=\"diff_next\" id=\"difflib_chg_to7__2\"></td><td class=\"diff_header\"></td><td nowrap=\"nowrap\"></td><td class=\"diff_next\"></td><td class=\"diff_header\" id=\"to7_5\">5</td><td nowrap=\"nowrap\"><span class=\"diff_add\">&nbsp;&nbsp;&nbsp;&nbsp;lat1&nbsp;=&nbsp;math.radians(lat1)</span></td></tr>\n",
              "            <tr><td class=\"diff_next\"></td><td class=\"diff_header\"></td><td nowrap=\"nowrap\"></td><td class=\"diff_next\"></td><td class=\"diff_header\" id=\"to7_6\">6</td><td nowrap=\"nowrap\"><span class=\"diff_add\">&nbsp;&nbsp;&nbsp;&nbsp;lon1&nbsp;=&nbsp;math.radians(lon1)</span></td></tr>\n",
              "            <tr><td class=\"diff_next\"></td><td class=\"diff_header\"></td><td nowrap=\"nowrap\"></td><td class=\"diff_next\"></td><td class=\"diff_header\" id=\"to7_7\">7</td><td nowrap=\"nowrap\"><span class=\"diff_add\">&nbsp;&nbsp;&nbsp;&nbsp;lat2&nbsp;=&nbsp;math.radians(lat2)</span></td></tr>\n",
              "            <tr><td class=\"diff_next\"></td><td class=\"diff_header\"></td><td nowrap=\"nowrap\"></td><td class=\"diff_next\"></td><td class=\"diff_header\" id=\"to7_8\">8</td><td nowrap=\"nowrap\"><span class=\"diff_add\">&nbsp;&nbsp;&nbsp;&nbsp;lon2&nbsp;=&nbsp;math.radians(lon2)</span></td></tr>\n",
              "            <tr><td class=\"diff_next\"></td><td class=\"diff_header\" id=\"from7_6\">6</td><td nowrap=\"nowrap\"></td><td class=\"diff_next\"></td><td class=\"diff_header\" id=\"to7_9\">9</td><td nowrap=\"nowrap\"></td></tr>\n",
              "            <tr><td class=\"diff_next\"><a href=\"#difflib_chg_to7__3\">n</a></td><td class=\"diff_header\" id=\"from7_7\">7</td><td nowrap=\"nowrap\"><span class=\"diff_sub\">&nbsp;&nbsp;Args:</span></td><td class=\"diff_next\"><a href=\"#difflib_chg_to7__3\">n</a></td><td class=\"diff_header\" id=\"to7_10\">10</td><td nowrap=\"nowrap\"><span class=\"diff_add\">&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;Calculate&nbsp;differences</span></td></tr>\n",
              "            <tr><td class=\"diff_next\" id=\"difflib_chg_to7__3\"></td><td class=\"diff_header\" id=\"from7_8\">8</td><td nowrap=\"nowrap\"><span class=\"diff_sub\">&nbsp;&nbsp;&nbsp;&nbsp;lat1:&nbsp;The&nbsp;latitude&nbsp;of&nbsp;the&nbsp;first&nbsp;point.</span></td><td class=\"diff_next\"></td><td class=\"diff_header\" id=\"to7_11\">11</td><td nowrap=\"nowrap\"><span class=\"diff_add\">&nbsp;&nbsp;&nbsp;&nbsp;dlat&nbsp;=&nbsp;lat2&nbsp;-&nbsp;lat1</span></td></tr>\n",
              "            <tr><td class=\"diff_next\"></td><td class=\"diff_header\" id=\"from7_9\">9</td><td nowrap=\"nowrap\"><span class=\"diff_sub\">&nbsp;&nbsp;&nbsp;&nbsp;lon1:&nbsp;The&nbsp;longitude&nbsp;of&nbsp;the&nbsp;first&nbsp;point.</span></td><td class=\"diff_next\"></td><td class=\"diff_header\" id=\"to7_12\">12</td><td nowrap=\"nowrap\"><span class=\"diff_add\">&nbsp;&nbsp;&nbsp;&nbsp;dlon&nbsp;=&nbsp;lon2&nbsp;-&nbsp;lon1</span></td></tr>\n",
              "            <tr><td class=\"diff_next\"></td><td class=\"diff_header\" id=\"from7_10\">10</td><td nowrap=\"nowrap\"><span class=\"diff_sub\">&nbsp;&nbsp;&nbsp;&nbsp;lat2:&nbsp;The&nbsp;latitude&nbsp;of&nbsp;the&nbsp;second&nbsp;point.</span></td><td class=\"diff_next\"></td><td class=\"diff_header\"></td><td nowrap=\"nowrap\"></td></tr>\n",
              "            <tr><td class=\"diff_next\"></td><td class=\"diff_header\" id=\"from7_11\">11</td><td nowrap=\"nowrap\"><span class=\"diff_sub\">&nbsp;&nbsp;&nbsp;&nbsp;lon2:&nbsp;The&nbsp;longitude&nbsp;of&nbsp;the&nbsp;second&nbsp;point.</span></td><td class=\"diff_next\"></td><td class=\"diff_header\"></td><td nowrap=\"nowrap\"></td></tr>\n",
              "            <tr><td class=\"diff_next\"></td><td class=\"diff_header\" id=\"from7_12\">12</td><td nowrap=\"nowrap\"></td><td class=\"diff_next\"></td><td class=\"diff_header\" id=\"to7_13\">13</td><td nowrap=\"nowrap\"></td></tr>\n",
              "            <tr><td class=\"diff_next\" id=\"difflib_chg_to7__4\"><a href=\"#difflib_chg_to7__4\">n</a></td><td class=\"diff_header\" id=\"from7_13\">13</td><td nowrap=\"nowrap\"><span class=\"diff_sub\">&nbsp;&nbsp;Returns:</span></td><td class=\"diff_next\"><a href=\"#difflib_chg_to7__4\">n</a></td><td class=\"diff_header\" id=\"to7_14\">14</td><td nowrap=\"nowrap\"><span class=\"diff_add\">&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;Calculate&nbsp;distance&nbsp;using&nbsp;Haversine&nbsp;formula</span></td></tr>\n",
              "            <tr><td class=\"diff_next\"></td><td class=\"diff_header\" id=\"from7_14\">14</td><td nowrap=\"nowrap\"><span class=\"diff_sub\">&nbsp;&nbsp;&nbsp;&nbsp;The&nbsp;distance&nbsp;between&nbsp;the&nbsp;two&nbsp;points&nbsp;in&nbsp;kilometers.</span></td><td class=\"diff_next\"></td><td class=\"diff_header\" id=\"to7_15\">15</td><td nowrap=\"nowrap\"><span class=\"diff_add\">&nbsp;&nbsp;&nbsp;&nbsp;a&nbsp;=&nbsp;math.sin(dlat&nbsp;/&nbsp;2)&nbsp;**&nbsp;2&nbsp;+&nbsp;math.cos(lat1)&nbsp;*&nbsp;math.cos(lat2)&nbsp;*&nbsp;math.sin(dlon&nbsp;/&nbsp;2)&nbsp;**&nbsp;2</span></td></tr>\n",
              "            <tr><td class=\"diff_next\"></td><td class=\"diff_header\" id=\"from7_15\">15</td><td nowrap=\"nowrap\"><span class=\"diff_sub\">&nbsp;&nbsp;\"\"\"</span></td><td class=\"diff_next\"></td><td class=\"diff_header\" id=\"to7_16\">16</td><td nowrap=\"nowrap\"><span class=\"diff_add\">&nbsp;&nbsp;&nbsp;&nbsp;c&nbsp;=&nbsp;2&nbsp;*&nbsp;math.atan2(math.sqrt(a),&nbsp;math.sqrt(1&nbsp;-&nbsp;a))</span></td></tr>\n",
              "            <tr><td class=\"diff_next\"></td><td class=\"diff_header\"></td><td nowrap=\"nowrap\"></td><td class=\"diff_next\"></td><td class=\"diff_header\" id=\"to7_17\">17</td><td nowrap=\"nowrap\"><span class=\"diff_add\">&nbsp;&nbsp;&nbsp;&nbsp;distance&nbsp;=&nbsp;6371&nbsp;*&nbsp;c&nbsp;&nbsp;#&nbsp;Earth's&nbsp;radius&nbsp;in&nbsp;kilometers</span></td></tr>\n",
              "            <tr><td class=\"diff_next\"></td><td class=\"diff_header\" id=\"from7_16\">16</td><td nowrap=\"nowrap\"></td><td class=\"diff_next\"></td><td class=\"diff_header\" id=\"to7_18\">18</td><td nowrap=\"nowrap\"></td></tr>\n",
              "            <tr><td class=\"diff_next\"><a href=\"#difflib_chg_to7__top\">t</a></td><td class=\"diff_header\" id=\"from7_17\">17</td><td nowrap=\"nowrap\"><span class=\"diff_sub\">&nbsp;&nbsp;#&nbsp;Convert&nbsp;the&nbsp;latitudes&nbsp;and&nbsp;longitudes&nbsp;to&nbsp;radians.</span></td><td class=\"diff_next\"><a href=\"#difflib_chg_to7__top\">t</a></td><td class=\"diff_header\"></td><td nowrap=\"nowrap\"></td></tr>\n",
              "            <tr><td class=\"diff_next\"></td><td class=\"diff_header\" id=\"from7_18\">18</td><td nowrap=\"nowrap\"><span class=\"diff_sub\">&nbsp;&nbsp;lat1&nbsp;=&nbsp;math.radians(lat1)</span></td><td class=\"diff_next\"></td><td class=\"diff_header\"></td><td nowrap=\"nowrap\"></td></tr>\n",
              "            <tr><td class=\"diff_next\"></td><td class=\"diff_header\" id=\"from7_19\">19</td><td nowrap=\"nowrap\"><span class=\"diff_sub\">&nbsp;&nbsp;lon1&nbsp;=&nbsp;math.radians(lon1)</span></td><td class=\"diff_next\"></td><td class=\"diff_header\"></td><td nowrap=\"nowrap\"></td></tr>\n",
              "            <tr><td class=\"diff_next\"></td><td class=\"diff_header\" id=\"from7_20\">20</td><td nowrap=\"nowrap\"><span class=\"diff_sub\">&nbsp;&nbsp;lat2&nbsp;=&nbsp;math.radians(lat2)</span></td><td class=\"diff_next\"></td><td class=\"diff_header\"></td><td nowrap=\"nowrap\"></td></tr>\n",
              "            <tr><td class=\"diff_next\"></td><td class=\"diff_header\" id=\"from7_21\">21</td><td nowrap=\"nowrap\"><span class=\"diff_sub\">&nbsp;&nbsp;lon2&nbsp;=&nbsp;math.radians(lon2)</span></td><td class=\"diff_next\"></td><td class=\"diff_header\"></td><td nowrap=\"nowrap\"></td></tr>\n",
              "            <tr><td class=\"diff_next\"></td><td class=\"diff_header\" id=\"from7_22\">22</td><td nowrap=\"nowrap\"><span class=\"diff_sub\">&nbsp;</span></td><td class=\"diff_next\"></td><td class=\"diff_header\"></td><td nowrap=\"nowrap\"></td></tr>\n",
              "            <tr><td class=\"diff_next\"></td><td class=\"diff_header\" id=\"from7_23\">23</td><td nowrap=\"nowrap\"><span class=\"diff_sub\">&nbsp;&nbsp;#&nbsp;Calculate&nbsp;the&nbsp;difference&nbsp;between&nbsp;the&nbsp;latitudes&nbsp;and&nbsp;longitudes.</span></td><td class=\"diff_next\"></td><td class=\"diff_header\"></td><td nowrap=\"nowrap\"></td></tr>\n",
              "            <tr><td class=\"diff_next\"></td><td class=\"diff_header\" id=\"from7_24\">24</td><td nowrap=\"nowrap\"><span class=\"diff_sub\">&nbsp;&nbsp;dlat&nbsp;=&nbsp;lat2&nbsp;-&nbsp;lat1</span></td><td class=\"diff_next\"></td><td class=\"diff_header\"></td><td nowrap=\"nowrap\"></td></tr>\n",
              "            <tr><td class=\"diff_next\"></td><td class=\"diff_header\" id=\"from7_25\">25</td><td nowrap=\"nowrap\"><span class=\"diff_sub\">&nbsp;&nbsp;dlon&nbsp;=&nbsp;lon2&nbsp;-&nbsp;lon1</span></td><td class=\"diff_next\"></td><td class=\"diff_header\"></td><td nowrap=\"nowrap\"></td></tr>\n",
              "            <tr><td class=\"diff_next\"></td><td class=\"diff_header\" id=\"from7_26\">26</td><td nowrap=\"nowrap\"><span class=\"diff_sub\">&nbsp;</span></td><td class=\"diff_next\"></td><td class=\"diff_header\"></td><td nowrap=\"nowrap\"></td></tr>\n",
              "            <tr><td class=\"diff_next\"></td><td class=\"diff_header\" id=\"from7_27\">27</td><td nowrap=\"nowrap\"><span class=\"diff_sub\">&nbsp;&nbsp;#&nbsp;Calculate&nbsp;the&nbsp;square&nbsp;of&nbsp;the&nbsp;sine&nbsp;of&nbsp;the&nbsp;half&nbsp;of&nbsp;the&nbsp;difference&nbsp;in&nbsp;latitude.</span></td><td class=\"diff_next\"></td><td class=\"diff_header\"></td><td nowrap=\"nowrap\"></td></tr>\n",
              "            <tr><td class=\"diff_next\"></td><td class=\"diff_header\" id=\"from7_28\">28</td><td nowrap=\"nowrap\"><span class=\"diff_sub\">&nbsp;&nbsp;sin_dlat_half&nbsp;=&nbsp;math.sin(dlat&nbsp;/&nbsp;2)&nbsp;**&nbsp;2</span></td><td class=\"diff_next\"></td><td class=\"diff_header\"></td><td nowrap=\"nowrap\"></td></tr>\n",
              "            <tr><td class=\"diff_next\"></td><td class=\"diff_header\" id=\"from7_29\">29</td><td nowrap=\"nowrap\"><span class=\"diff_sub\">&nbsp;</span></td><td class=\"diff_next\"></td><td class=\"diff_header\"></td><td nowrap=\"nowrap\"></td></tr>\n",
              "            <tr><td class=\"diff_next\"></td><td class=\"diff_header\" id=\"from7_30\">30</td><td nowrap=\"nowrap\"><span class=\"diff_sub\">&nbsp;&nbsp;#&nbsp;Calculate&nbsp;the&nbsp;square&nbsp;of&nbsp;the&nbsp;sine&nbsp;of&nbsp;the&nbsp;half&nbsp;of&nbsp;the&nbsp;difference&nbsp;in&nbsp;longitude.</span></td><td class=\"diff_next\"></td><td class=\"diff_header\"></td><td nowrap=\"nowrap\"></td></tr>\n",
              "            <tr><td class=\"diff_next\"></td><td class=\"diff_header\" id=\"from7_31\">31</td><td nowrap=\"nowrap\"><span class=\"diff_sub\">&nbsp;&nbsp;sin_dlon_half&nbsp;=&nbsp;math.sin(dlon&nbsp;/&nbsp;2)&nbsp;**&nbsp;2</span></td><td class=\"diff_next\"></td><td class=\"diff_header\"></td><td nowrap=\"nowrap\"></td></tr>\n",
              "            <tr><td class=\"diff_next\"></td><td class=\"diff_header\" id=\"from7_32\">32</td><td nowrap=\"nowrap\"><span class=\"diff_sub\">&nbsp;</span></td><td class=\"diff_next\"></td><td class=\"diff_header\"></td><td nowrap=\"nowrap\"></td></tr>\n",
              "            <tr><td class=\"diff_next\"></td><td class=\"diff_header\" id=\"from7_33\">33</td><td nowrap=\"nowrap\"><span class=\"diff_sub\">&nbsp;&nbsp;#&nbsp;Calculate&nbsp;the&nbsp;square&nbsp;of&nbsp;the&nbsp;great-circle&nbsp;distance&nbsp;between&nbsp;the&nbsp;two&nbsp;points.</span></td><td class=\"diff_next\"></td><td class=\"diff_header\"></td><td nowrap=\"nowrap\"></td></tr>\n",
              "            <tr><td class=\"diff_next\"></td><td class=\"diff_header\" id=\"from7_34\">34</td><td nowrap=\"nowrap\"><span class=\"diff_sub\">&nbsp;&nbsp;a&nbsp;=&nbsp;sin_dlat_half&nbsp;+&nbsp;math.cos(lat1)&nbsp;*&nbsp;math.cos(lat2)&nbsp;*&nbsp;sin_dlon_half</span></td><td class=\"diff_next\"></td><td class=\"diff_header\"></td><td nowrap=\"nowrap\"></td></tr>\n",
              "            <tr><td class=\"diff_next\"></td><td class=\"diff_header\" id=\"from7_35\">35</td><td nowrap=\"nowrap\"><span class=\"diff_sub\">&nbsp;</span></td><td class=\"diff_next\"></td><td class=\"diff_header\"></td><td nowrap=\"nowrap\"></td></tr>\n",
              "            <tr><td class=\"diff_next\"></td><td class=\"diff_header\" id=\"from7_36\">36</td><td nowrap=\"nowrap\"><span class=\"diff_sub\">&nbsp;&nbsp;#&nbsp;Calculate&nbsp;the&nbsp;great-circle&nbsp;distance&nbsp;between&nbsp;the&nbsp;two&nbsp;points.</span></td><td class=\"diff_next\"></td><td class=\"diff_header\"></td><td nowrap=\"nowrap\"></td></tr>\n",
              "            <tr><td class=\"diff_next\"></td><td class=\"diff_header\" id=\"from7_37\">37</td><td nowrap=\"nowrap\"><span class=\"diff_sub\">&nbsp;&nbsp;c&nbsp;=&nbsp;2&nbsp;*&nbsp;math.asin(math.sqrt(a))</span></td><td class=\"diff_next\"></td><td class=\"diff_header\"></td><td nowrap=\"nowrap\"></td></tr>\n",
              "            <tr><td class=\"diff_next\"></td><td class=\"diff_header\" id=\"from7_38\">38</td><td nowrap=\"nowrap\"><span class=\"diff_sub\">&nbsp;</span></td><td class=\"diff_next\"></td><td class=\"diff_header\"></td><td nowrap=\"nowrap\"></td></tr>\n",
              "            <tr><td class=\"diff_next\"></td><td class=\"diff_header\" id=\"from7_39\">39</td><td nowrap=\"nowrap\"><span class=\"diff_sub\">&nbsp;&nbsp;#&nbsp;Calculate&nbsp;the&nbsp;Earth's&nbsp;radius&nbsp;in&nbsp;kilometers.</span></td><td class=\"diff_next\"></td><td class=\"diff_header\"></td><td nowrap=\"nowrap\"></td></tr>\n",
              "            <tr><td class=\"diff_next\"></td><td class=\"diff_header\" id=\"from7_40\">40</td><td nowrap=\"nowrap\"><span class=\"diff_sub\">&nbsp;&nbsp;r&nbsp;=&nbsp;6371</span></td><td class=\"diff_next\"></td><td class=\"diff_header\"></td><td nowrap=\"nowrap\"></td></tr>\n",
              "            <tr><td class=\"diff_next\"></td><td class=\"diff_header\" id=\"from7_41\">41</td><td nowrap=\"nowrap\"><span class=\"diff_sub\">&nbsp;</span></td><td class=\"diff_next\"></td><td class=\"diff_header\"></td><td nowrap=\"nowrap\"></td></tr>\n",
              "            <tr><td class=\"diff_next\"></td><td class=\"diff_header\" id=\"from7_42\">42</td><td nowrap=\"nowrap\"><span class=\"diff_sub\">&nbsp;&nbsp;#&nbsp;Calculate&nbsp;the&nbsp;distance&nbsp;between&nbsp;the&nbsp;two&nbsp;points&nbsp;in&nbsp;kilometers.</span></td><td class=\"diff_next\"></td><td class=\"diff_header\"></td><td nowrap=\"nowrap\"></td></tr>\n",
              "            <tr><td class=\"diff_next\"></td><td class=\"diff_header\" id=\"from7_43\">43</td><td nowrap=\"nowrap\"><span class=\"diff_sub\">&nbsp;&nbsp;distance&nbsp;=&nbsp;r&nbsp;*&nbsp;c</span></td><td class=\"diff_next\"></td><td class=\"diff_header\"></td><td nowrap=\"nowrap\"></td></tr>\n",
              "            <tr><td class=\"diff_next\"></td><td class=\"diff_header\" id=\"from7_44\">44</td><td nowrap=\"nowrap\"><span class=\"diff_sub\">&nbsp;</span></td><td class=\"diff_next\"></td><td class=\"diff_header\"></td><td nowrap=\"nowrap\"></td></tr>\n",
              "            <tr><td class=\"diff_next\"></td><td class=\"diff_header\" id=\"from7_45\">45</td><td nowrap=\"nowrap\">&nbsp;&nbsp;return&nbsp;distance</td><td class=\"diff_next\"></td><td class=\"diff_header\" id=\"to7_19\">19</td><td nowrap=\"nowrap\"><span class=\"diff_add\">&nbsp;&nbsp;</span>&nbsp;&nbsp;return&nbsp;distance</td></tr>\n",
              "            <tr><td class=\"diff_next\"></td><td class=\"diff_header\" id=\"from7_46\">46</td><td nowrap=\"nowrap\"><span class=\"diff_sub\">```</span></td><td class=\"diff_next\"></td><td class=\"diff_header\"></td><td nowrap=\"nowrap\"></td></tr>\n",
              "        </tbody>\n",
              "    </table>\n",
              "</body>\n",
              "\n",
              "</html>"
            ]
          },
          "metadata": {},
          "execution_count": 18
        }
      ]
    }
  ]
}